package com.sau.pixelcart.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.sau.pixelcart.domain.entity.OrderDetail;
import com.sau.pixelcart.domain.vo.OrderDetailVO;
import com.sau.pixelcart.mapper.OrderDetailMapper;
import com.sau.pixelcart.service.IOrderDetailService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 订单商品明细（建议按月分表存储） 服务实现类
 * </p>
 *
 * @author Inton
 * @since 2025-03-27
 */
@Service
public class OrderDetailServiceImpl extends ServiceImpl<OrderDetailMapper, OrderDetail> implements IOrderDetailService {

    private final OrderDetailMapper orderDetailMapper;

    public OrderDetailServiceImpl(OrderDetailMapper orderDetailMapper) {
        this.orderDetailMapper = orderDetailMapper;
    }

    /**
     * 查看订单详情
     *
     * @param ordersId
     * @return
     */
    @Override
    public List<OrderDetailVO> getByOrdersId(String ordersId) {
        LambdaQueryWrapper<OrderDetail> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(OrderDetail::getOrderId,ordersId);

        List<OrderDetail> orderDetailList = orderDetailMapper.selectList(lambdaQueryWrapper);
        List<OrderDetailVO> orderDetailVOList = orderDetailList.stream().map(orderDetail -> {
            OrderDetailVO orderDetailVO = new OrderDetailVO();
            BeanUtils.copyProperties(orderDetail, orderDetailVO);
            return orderDetailVO;
        }).collect(Collectors.toList());
        return orderDetailVOList;
    }
}
